import great_expectations as gx
from sqlalchemy.dialects.postgresql.base import PGDialect
PGDialect._get_server_version_info=lambda  *args: (9,2)

context = gx.get_context()

datasource_name = "my_datasource"
my_connection_string="postgresql+psycopg2://${user}:${password}@${localhost}:${port}/demo"


data_source = context.data_sources.add_postgres(
    name=datasource_name, connection_string=my_connection_string
)
data_asset =data_source.add_table_asset(
    name="my_table",table_name="your_table_name"
)


batch_definition = data_asset.add_batch_definition_whole_table("batch definition")
batch = batch_definition.get_batch()

suite = context.suites.add(
    gx.core.expectation_suite.ExpectationSuite(name="expectations")
)
suite.add_expectation(
    gx.expectations.ExpectColumnValuesToBeBetween(
        column="qty", min_value=0, max_value=4
    )
)
validation_definition = context.validation_definitions.add(
    gx.core.validation_definition.ValidationDefinition(
        name="validation definition",
        data=batch_definition,
        suite=suite,
    )
)
checkpoint = context.checkpoints.add(
    gx.checkpoint.checkpoint.Checkpoint(
        name="checkpoint", validation_definitions=[validation_definition]
    )
)

checkpoint_result = checkpoint.run()
print(checkpoint_result.describe())